package cn.rkylin.oms.warehouse.local.returnStockin.dao;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.warehouse.local.returnStockin.domain.ReturnStockin;
import cn.rkylin.oms.warehouse.local.returnStockin.vo.ReturnStockinVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 退货入库单DAO
 *
 * @author 齐涛
 * @version 1.0
 * @created 28-9-2017 10:51:30
 */
@Repository(value = "localReturnStockinDAO")
public class ReturnStockinDAOImpl implements ReturnStockinDAO {

    @Autowired
    protected IDataBaseFactory dao;

    /**
     * 查询退货入库单信息
     *
     * @param returnStockinVO 退货入库单VO
     * @return 退货入库单信息
     * @throws Exception 异常
     */
    public ReturnStockinVO getReturnStockinInfo(ReturnStockinVO returnStockinVO) throws Exception {
        List<ReturnStockinVO> list = dao.findAllList("getReturnLocalStockInInfo", returnStockinVO);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    /**
     * 更新退货入库单
     *
     * @param returnStockin 退货入库单bean
     * @return 更新条数
     * @throws Exception 异常
     */
    public int updateReturnStockin(ReturnStockin returnStockin) throws Exception {
        return dao.update("updateLocalReturnStockin", returnStockin);
    }

    /**
     * 通过来源ID获取退货入库单信息 wangxing add
     *
     * @param strSourceId
     * @return
     * @throws Exception
     */
    public ReturnStockinVO getReturnStockInInfoBySourceId(String strSourceId) throws Exception {
        List<ReturnStockinVO> list = dao.findList("getReturnStockInInfoBySourceId", strSourceId);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    @Override
    public int getUnGoingCount(Map<String, String> paramMap) throws Exception {
        return dao.findOne("selectUnGoingReturnStockIn", paramMap);
    }

}
